using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Toenda.Rails.Data;
using Toenda.Rails.DataContainer;
using Toenda.TFL.Base;
using Toenda.TFL.Data;

namespace Toenda.Rails {
	namespace Data {
		public class DBContent : DBClient {
			// ---------------------------------------------------------
			// CONSTRUCTORS
			// ---------------------------------------------------------

			/// <summary>
			/// Default constructor
			/// </summary>
			public DBContent() {
			}

			// ---------------------------------------------------------
			// PUBLIC MEMBERS
			// ---------------------------------------------------------

			/// <summary>
			/// Save a vulnerability message
			/// </summary>
			/// <param name="item"></param>
			/// <returns></returns>
			public ErrorType SaveVulnerabilityMessage(MessageItem item) {
				StringBuilder str = new StringBuilder();

				str.Append("SELECT * FROM [dbo].[tbl_vulnerability]");
				str.Append(" WHERE [pkid] = '" + item.ID + "'");

				DataSet dsData = DBBaseClass.ExecuteQuery(str.ToString());
				DataRow row = null;
				
				if(dsData.Tables[0].Rows.Count == 0) {
					row = dsData.Tables[0].NewRow();
				}
				else {
					row = dsData.Tables[0].Rows[0];
				}

				row["pkid"] = item.ID + "";
				row["image_id"] = item.ImageID + "";
				row["description"] = item.Description + "";
				row["is_finished"] = item.IsFinished;
				row["create_date"] = item.CreateDate;
				row["sender_email"] = item.EMail;

				if(dsData.Tables[0].Rows.Count == 0) {
					dsData.Tables[0].Rows.Add(row);
				}

				int iResult = base.DBBaseClass.ExecuteUpdate(dsData, "tbl_vulnerability");

				return ErrorType.NoError;
			}
		}
	}
}
